package com.beiing.tianshuai.tianshuai.activity;

import android.content.Intent;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.beiing.tianshuai.tianshuai.R;
import com.beiing.tianshuai.tianshuai.base.BaseActivity;
import com.beiing.tianshuai.tianshuai.widget.ZoomImageView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

public class SinglePicPreviewActivity extends BaseActivity {

    @BindView(R.id.ziv_image_container)
    ZoomImageView mZivImageContainer;
    @BindView(R.id.toolbar_navigation)
    ImageView mToolbarNavigation;
    @BindView(R.id.toolbar_title)
    TextView mToolbarTitle;
    @BindView(R.id.toolbar)
    Toolbar mToolbar;

    private Unbinder mUnbinder;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_single_pic_preview;
    }

    @Override
    protected void init() {
        mUnbinder = ButterKnife.bind(this);
        initStatusBar();
        initListener();
        getImage();
    }

    private void initStatusBar() {
//        XStatusBarHelper.forceFitsSystemWindows(this);
//        XStatusBarHelper.immersiveStatusBar(this);
//        XStatusBarHelper.setHeightAndPadding(this, mToolbar);
//        XStatusBarHelper.setStatusBarDarkMode(this);
    }

    private void initListener() {

        mToolbarNavigation.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        mToolbarTitle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

    private void getImage() {
        Intent intent = getIntent();
        String url = intent.getStringExtra("avatarUrl");
        RequestOptions requestOptions = new RequestOptions()
                .diskCacheStrategy(DiskCacheStrategy.RESOURCE)
                .fitCenter()
                .override(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        Glide.with(this)
                .load(url)
                .apply(requestOptions)
                .into(mZivImageContainer);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mUnbinder.unbind();
    }
}
